﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Panny.Data;
using System.ComponentModel;
namespace Controller
{
    public class InformationShow
    {
        #region index.aspx
        public DataSet GetIndexInfo()
        {
            string sql = "select top 10 Title,InfoDate,InfoID from informations order by CONVERT(varchar(10),InfoDate,126) desc,hits";
            using (SqlText selection = new SqlText(sql))
            {
                return selection.GetDataset();
            }
        }

        public DataSet GetRight_Iframe(string citycode)
        {
            string sql = "select top 8 Title,InfoDate,InfoID,InfoType from informations where AreaID=@AreaID order by CONVERT(varchar(10),InfoDate,126) desc,hits";
            using (SqlText selection = new SqlText(sql))
            {
                selection.AddParameter("@AreaID", citycode);
                return selection.GetDataset();
            } 
        }
        public DataSet GetRight_Iframe_Index(int top,string citycode,string typeid)
        {
            string sql = "select top {0} Title,InfoDate,InfoID,InfoType from informations where AreaID=@AreaID and CorpTypeID=@TypeID order by CONVERT(varchar(10),InfoDate,126) desc,hits desc";
            using (SqlText selection = new SqlText(string.Format(sql,top)))
            {
                selection.AddParameter("@AreaID", citycode);
                selection.AddParameter("@TypeID", typeid);
                return selection.GetDataset();
            }
        }
        #endregion

        #region article.aspx
        public Entity.Informations SelectSingle(string infoID)
        {
            string sql = @"UPDATE Informations set hits=hits+1 WHERE InfoID =@InfoID 
                        SELECT [InfoID], [InfoType], [source], [ImageUrl], [Body], [Title]
                        FROM [Informations] 
                        WHERE InfoID =@InfoID";
            Entity.Informations info = new Entity.Informations();
            using (SqlText selection = new SqlText(sql))
            {
                selection.AddParameter("@InfoID", infoID);
                while (selection.Read())
                {
                    info.InfoID =  Convert.ToInt32(selection["InfoID"].ToString());
                    info.Title = selection["Title"].ToString();
                    info.Body = selection["Body"].ToString();
                }
                return info;
            }
        }

        public DataSet GetArticleTop5(int top, string citycode, string typeid)
        {
            string sql = "select top {0} Title,InfoDate,InfoID,InfoType from informations where AreaID=@AreaID and CorpTypeID=@TypeID order by hits desc";
            using (SqlText selection = new SqlText(string.Format(sql, top)))
            {
                selection.AddParameter("@AreaID", citycode);
                selection.AddParameter("@TypeID", typeid);
                return selection.GetDataset();
            }
        }

        #endregion
    }
}
